package javads;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

interface Star {
    void show();
}

class Singer implements Star {
    @Override
    public void show() {
        System.out.println("唱首歌~~~");
    }
}

public class ProxyClient implements InvocationHandler {
    private Star star;
    public ProxyClient(Star star) {
        this.star = star;
    }

    @Override
    public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
        return method.invoke(star);
    }
    public static void main(String[] args) {
        System.getProperties().put("sun.misc.ProxyGenerator.saveGeneratedFiles", "true");

        Singer singer = new Singer();
        ProxyClient proxyClient = new ProxyClient(singer);

        Star star = (Star) Proxy.newProxyInstance(
                singer.getClass().getClassLoader(),
                singer.getClass().getInterfaces(),
                proxyClient
        );
        star.show();
    }
}


